/** 
 * Copyright (C), 2010-2012, TIETIAO Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:BgCommodityAction.java
 * Version:1.0
 * Date:2012-1-3
 * Description: 后台用户商品管理ACTION
 * author:zhijian.zhang
 */
package com.tietiao.action.bg;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.tietiao.common.action.BaseAction;
import com.tietiao.common.json.JsonControllerHelper;
import com.tietiao.common.util.PageModel;
import com.tietiao.dao.model.CommodityInfo;
import com.tietiao.service.commodity.CommodityService;

@Controller
@Scope("prototype")
@SuppressWarnings("serial")
public class BgCommodityAction extends BaseAction {
	@Resource
	private CommodityService commodityService;
	// 商品信息（接受表单信息）
	private CommodityInfo commodityInfo;
	// 商品列表信息
	private List<CommodityInfo> commodityInfos;
	
	// 需要删除的商品ID 多个ID以逗号相隔
	private String commodityIds;

	public String getCommodityIds() {
		return commodityIds;
	}

	public void setCommodityIds(String commodityIds) {
		this.commodityIds = commodityIds;
	}

	public CommodityInfo getCommodityInfo() {
		return commodityInfo;
	}

	public void setCommodityInfo(CommodityInfo commodityInfo) {
		this.commodityInfo = commodityInfo;
	}

	public List<CommodityInfo> getCommodityInfos() {
		return commodityInfos;
	}

	public void setCommodityInfos(List<CommodityInfo> commodityInfos) {
		this.commodityInfos = commodityInfos;
	}

	// 进入商品管理主页
	public String index() {
		return dispatcher("/jsp/bg/commodity/commodity_list.jsp");
	}

	// 加载数据
	public String loadList() throws Exception{
		PageModel<CommodityInfo> pages = commodityService
				.getPageModelCommodityInfosForBg(commodityInfo, getStart(),
						getLimit(), getSort(), getDir());
		
		JsonControllerHelper.writePageModelToResponse(response, pages);
		return null;
	}

	// 删除数据
	public String del() {
		commodityService.delCommodityForBg(commodityIds);
		return null;
	}
}
